package com.jfinal.plugin.radius;

import com.jfinal.plugin.radius.util.RadiusClient;

/**
 * 一个简单的 Radius客户端调用示例.
 */
public class TestClient {

	public static void main(String[] args) 
	throws Exception {

		String host = "192.168.198.132";
		String shared = "wifibeijing";
		String user = "test3";
		String pass = "123456";

		RadiusClient rc = new RadiusClient(host, shared);

		if(rc.authenticate(user, pass)){
			System.out.println("认证成功！\n");	
		}
//		// 1. Send Access-Request
//		AccessRequest ar = new AccessRequest(user, pass);
//		ar.setAuthProtocol(AccessRequest.AUTH_CHAP); // or AUTH_PAP
//		ar.addAttribute("NAS-Identifier", "this.is.my.nas-identifier.de");
//		ar.addAttribute("NAS-IP-Address", "192.168.0.100");
//		ar.addAttribute("Service-Type", "Login-User");
//		ar.addAttribute("WISPr-Redirection-URL", "http://www.sourceforge.net/");
//		ar.addAttribute("WISPr-Location-ID", "net.sourceforge.ap1");
//		
//		System.out.println("Packet before it is sent\n" + ar + "\n");
//		RadiusPacket response = rc.authenticate(ar);
//		System.out.println("Packet after it was sent\n" + ar + "\n");
//		System.out.println("Response\n" + response + "\n");
//
//		// 2. Send Accounting-Request
//		AccountingRequest acc = new AccountingRequest("mw", AccountingRequest.ACCT_STATUS_TYPE_START);
//		acc.addAttribute("Acct-Session-Id", "1234567890");
//		acc.addAttribute("NAS-Identifier", "this.is.my.nas-identifier.de");
//		acc.addAttribute("NAS-Port", "0");
//	
//		System.out.println(acc + "\n");	
//		response = rc.account(acc);
//		System.out.println("Response: " + response);
		
		rc.close();
	}
	
}
